/* test.cpp
*/

#include <fstream>
#include <sstream>
#include <string.h>
#include <iostream>
#include <stdlib.h>
#include <ctype.h>

using namespace std;

int check(char *str1, char *str2, int *anagram)
{
  int *comp;
  comp = new int[256];
  for(int i=0;i<256;i++)
    *(comp+i) = 0;

  int m=0;
  while(*(str1+m) !=0)
  {
    cout << *(str1+m);
    m++;
  }
  m=0;
  cout<< "\n";
  while(*(str2+m) !=0)
  {
    cout << *(str2+m);
    m++;
  }
  cout << "\n";

  int n=0;
  int tmp;
  while(*(str1+n)!=0)
  {
    tmp = *(comp+(int)(tolower(*(str1+n))));
    tmp++;
    *(comp+(int)(tolower(*(str1+n)))) = tmp;
    n++;
  }

  n=0;
  while(*(str2+n)!=0)
  {
    if(*(str2+n)!=' ')
    {
      tmp = *(comp+(int)(tolower(*(str2+n))));
      tmp--;
      *(comp+(int)(tolower(*(str2+n)))) = tmp;
//      n++;
    }
    n++;
  }

  for (int i=0;i<256;i++)
  {
    if(*(comp+i)!=0)
    {
      *anagram = -1;
      break;
    }
  }

  delete[] comp;

  return 0;
}

int main(int argc, char *argv[])
{
  if(argc<2)
  {
    cout << "no testcase file input\n";
    return 0;
  }

  char *filename = argv[1];
  ifstream infile(filename);
  char *str1;
  str1 = (char *)malloc(256*sizeof(char));
  char *str2;
  str2 = (char *)malloc(256*sizeof(char));
  string in;
  getline(infile, in);
  istringstream ss(in);
  int num;
  ss >> num;
  cout << "test case number is: " << num << endl;
  int i=1;
  while(getline(infile,in) && i<=num)
  {
    int len = in.size();
    int n = 0;
    for(int j=0; j<len; j++)
    {
      if (in[j] == ' ')
      {  
        n = j;
        break;
      }
    }
    for(int j=0;j<n;j++)
      *(str1+j) = in[j];
    *(str1+n) = 0;
    for(int j=0;j<len-n;j++)
      *(str2+j) = in[j+n];
    *(str2+len-n) = 0;

    int *anagram;
    anagram = (int *)malloc(sizeof(int));
    *anagram = 0;
    check(str1, str2, anagram);
    if (*anagram >= 0)
      cout << "True\n";
    else
      cout << "False\n";

    cout << *anagram << endl;
    memset(str1, 0, len);
    memset(str2, 0, len);
    free(anagram);
    cout << "----------------------\n";
    i++;
  }

  free(str1);
  free(str2);
  return 0;
}
